package com.appkubes.mall.admin.application.promoter.statis.dao;

import com.appkubes.mall.admin.application.promoter.statis.entity.dto.PromoterStatisDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface PromoterStatisDao {

    @Select({"select mp.promoter_key, mp.promoter_name, mu.`name`, mu.create_time, mu.id_card, mu.tel,",
            "    muh.user_key, muh.parent_user_key, parent_user.tel as parent_tel, parent_user.`name` as parent_name, utm.platform_type ",
            " from  mall_promoter mp ",
            "     join mall_user_hierarchy muh on  muh.promoter_key = mp.promoter_key  ",
            "     left join mall_user mu on mu.user_key = muh.user_key",
            "     left join mall_user parent_user on parent_user.user_key = muh.parent_user_key ",
            "     left join mall_user_utm utm on utm.user_key = mu.user_key",
            " where mp.promoter_key = #{promoterKey}" +
            " order by mu.create_time desc"})
    IPage<PromoterStatisDTO> selectPromoterStatis(IPage<PromoterStatisDTO> page, @Param("promoterKey") String promoterKey);

}
